﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_payment_terms
{
    public DAL_tbl_payment_terms()
    {

    }



    public List<tbl_payment_terms> select(int PAYMENT_TERM_ID)
    {
        List<tbl_payment_terms> list = new List<tbl_payment_terms>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select PAYMENT_TERM_ID,PAYMENT_TERM,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_payment_terms where PAYMENT_TERM_ID=@PAYMENT_TERM_ID";
        cmd.Parameters.AddWithValue("@PAYMENT_TERM_ID", PAYMENT_TERM_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_payment_terms()
            {
                PAYMENT_TERM_ID = Convert.ToInt32(dr["PAYMENT_TERM_ID"]),
                PAYMENT_TERM = dr["PAYMENT_TERM"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_payment_terms> selectAll()
    {
        List<tbl_payment_terms> list = new List<tbl_payment_terms>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select PAYMENT_TERM_ID,PAYMENT_TERM,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_payment_terms Order By PAYMENT_TERM_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_payment_terms()
            {
                PAYMENT_TERM_ID = Convert.ToInt32(dr["PAYMENT_TERM_ID"]),
                PAYMENT_TERM = dr["PAYMENT_TERM"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String PAYMENT_TERM, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_payment_terms(PAYMENT_TERM, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@PAYMENT_TERM, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PAYMENT_TERM", PAYMENT_TERM);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int PAYMENT_TERM_ID, String PAYMENT_TERM, bool IS_ACTIVE, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_payment_terms SET PAYMENT_TERM=@PAYMENT_TERM, IS_ACTIVE=@IS_ACTIVE, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE PAYMENT_TERM_ID=@PAYMENT_TERM_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PAYMENT_TERM_ID", PAYMENT_TERM_ID);
        cmd.Parameters.AddWithValue("@PAYMENT_TERM", PAYMENT_TERM);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int PAYMENT_TERM_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_payment_terms WHERE PAYMENT_TERM_ID=@PAYMENT_TERM_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PAYMENT_TERM_ID", PAYMENT_TERM_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}